/**   
 * @Title: EditTextInputUitl.java 
 * @Package: com.esun.util 
 * @Description: 适用于带删除按钮的EditText 
 * @Author: Miko baoz@500wan.com   
 * @Date: 2011-7-6 下午05:22:33  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.util;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

/**
 * 
 * @Package com.esun.util.EditTextInputUitl
 * @ClassName: EditTextInputUitl
 * @Description: TODO(EditText工具类)
 * @author 韩昕桐 <br/>
 * @date create at 2012-4-5 上午10:19:11
 * 
 */
public class EditTextInputUitl implements TextWatcher, OnClickListener {

	private EditText et;
	private Button btn;

	public EditTextInputUitl(EditText et, Button btn) {

		this.et = et;
		this.btn = btn;

		this.btn.setOnClickListener(this);
		this.btn.setVisibility(View.GONE);
		this.et.addTextChangedListener(this);

	}

	public EditText getEditText() {
		return et;
	}

	@Override
	public void afterTextChanged(Editable s) {

	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		if (et.getText().toString().length() > 0) {
			btn.setVisibility(View.VISIBLE);
		} else {
			btn.setVisibility(View.GONE);
		}
	}

	@Override
	public void onClick(View v) {
		et.setText("");
		v.setVisibility(View.GONE);
	}

}
